﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Store_Manager_SM_ChangePW : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["current"] = "Change Password";//current page
        if (Session["user"] != null)//check user
        {
            string user = Session["user"].ToString();
            if (user == "viewer")
            {
                Response.Redirect("index.aspx");
            }

        }
        else
        {
            Response.Redirect("index.aspx");
        }
    }
    protected void btn_update_Click(object sender, EventArgs e)
    {
       string oldpw=txt_cpassword.Text;
       string newpw = txt_npassword.Text;
       string newre = txt_ccpassword.Text;
        Bestlife.ERP.Entities.Login user=new Bestlife.ERP.Entities.Login();
        user.User_Name1 = Session["username"].ToString();
        user.Password1=newpw;
        string currentpw=Bestlife.ERP.BusinessRules.userlogin.pw(user);
        if (currentpw == oldpw)
        {
            if (newpw == newre)
            {
             Boolean result=Bestlife.ERP.BusinessRules.userlogin.upd_pw(user);
             if (result)
             {
                 ASPxLabel2.Text = "Password Changed Sucessfully!!";
             }
            }
            else
            {
                lbl_msg.Text = "Password Mismatch";
            }
        }
        else
        {
            lbl_msg.Text = "Current Password is Incorrect!!";
        }
    }
}